package cn.fourhundredandeighteen.utill;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**

 */
public class NumberUtil {

    private NumberUtil() {
    }


    /**
     * 判断是否为11位电话号码
     *
     * @param phone
     * @return
     */
    public static boolean isPhone(String phone) {
        Pattern pattern = Pattern.compile("^((13[0-9])|(14[5,7])|(15[^4,\\D])|(17[0-8])|(18[0-9]))\\d{8}$");
        Matcher matcher = pattern.matcher(phone);
        return matcher.matches();
    }

    /**
     * 判断密码字段是否合适
     *
     * @param Password
     * @return
     */
    public static boolean Password(String Password) {
        Pattern pattern = Pattern.compile("^\\d{6}$");
        Matcher matcher = pattern.matcher(Password);
        return matcher.matches();
    }

    /**
     * 判断年龄
     *
     * @param
     * @return
     */
    public static boolean Age(String age) {
        if (Integer.valueOf(age) < 53 && Integer.valueOf(age) > 15) {
            return false;
        }
        return true;
    }

    /**
     * 判断性别
     *
     * @param
     * @return
     */
    public static boolean Major(String Major) {
        if (Major != "男" || Major != "女") {
            return true;
        }
        return false;
    }

    /**
     * 生成指定长度的随机数
     *
     * @param length
     * @return
     */
    public static Long genRandomNum(int length) {
        int num = 1;
        double random = Math.random();
        if (random < 0.1) {
            random = random + 0.1;
        }
        for (int i = 0; i < length; i++) {
            num = num * 10;
        }
        int v = (int) (random * num);
        return Long.valueOf(v);
    }

    /**
     * 生成订单流水号
     *
     * @return
     */
    public static String genOrderNo() {
        StringBuffer buffer = new StringBuffer(String.valueOf(System.currentTimeMillis()));
        long num = genRandomNum(4);
        buffer.append(num);
        return buffer.toString();
    }

    public static Long genNo() {
        StringBuffer buffer = new StringBuffer(String.valueOf(System.currentTimeMillis()));
        long num = genRandomNum(6);
        return num;
    }
}
